package com.leyou.search.controller;

import com.leyou.common.pojo.PageResult;
import com.leyou.search.pojo.Goods;
import com.leyou.search.pojo.SearchRequest;
import com.leyou.search.pojo.Searchresult;
import com.leyou.search.service.GoodsService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shkstart
 * @create 2020-04-25 10:56
 */
@RestController
public class SearchController {

    @Autowired
    GoodsService goodsService;

    @RequestMapping("page")
    public ResponseEntity<Searchresult> getPage(@RequestBody SearchRequest searchRequest){

        Searchresult PageList =  goodsService.searchByKey(searchRequest);
        if (CollectionUtils.isEmpty(PageList.getItems())){
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(PageList);
    }


}
